package com.localjoycommunity.cpdj.project.system.controller;

import com.localjoycommunity.cpdj.common.utils.poi.ExcelUtil;
import com.localjoycommunity.cpdj.framework.aspectj.lang.annotation.Log;
import com.localjoycommunity.cpdj.framework.aspectj.lang.enums.BusinessType;
import com.localjoycommunity.cpdj.framework.web.controller.BaseController;
import com.localjoycommunity.cpdj.framework.web.domain.AjaxResult;
import com.localjoycommunity.cpdj.framework.web.page.TableDataInfo;
import com.localjoycommunity.cpdj.project.system.domain.PartyBranch;
import com.localjoycommunity.cpdj.project.system.service.IPartyBranchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 党支部Controller
 *
 * @author leepandar
 * @date 2020-11-04
 */
@RestController
@RequestMapping("/system/branch")
public class PartyBranchController extends BaseController {
    @Autowired
    private IPartyBranchService partyBranchService;

    /**
     * 查询党支部列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PartyBranch partyBranch) {
        startPage();
        List<PartyBranch> list = partyBranchService.selectPartyBranchList(partyBranch);
        return getDataTable(list);
    }

    /**
     * 导出党支部列表
     */
    @Log(title = "党支部", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PartyBranch partyBranch) {
        List<PartyBranch> list = partyBranchService.selectPartyBranchList(partyBranch);
        ExcelUtil<PartyBranch> util = new ExcelUtil<PartyBranch>(PartyBranch.class);
        return util.exportExcel(list, "branch");
    }

    /**
     * 获取党支部详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(partyBranchService.selectPartyBranchById(id));
    }

    /**
     * 新增党支部
     */
    @Log(title = "党支部", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PartyBranch partyBranch) {
        return toAjax(partyBranchService.insertPartyBranch(partyBranch));
    }

    /**
     * 修改党支部
     */
    @Log(title = "党支部", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PartyBranch partyBranch) {
        return toAjax(partyBranchService.updatePartyBranch(partyBranch));
    }

    /**
     * 删除党支部
     */
    @Log(title = "党支部", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(partyBranchService.deletePartyBranchByIds(ids));
    }
}
